package com.happy.ibidding.service;

import com.happy.ibidding.bean.User;
import com.happy.ibidding.dao.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {

    final private UserRepository userRepository;

    @Autowired
    public UserService(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    public User saveUser(User user) {
        return this.userRepository.save(user);
    }

    public User findUserByUserId(String userId) {
        return this.userRepository.findByUserId(userId);
    }

    public User findUserById(String mongodbId){
        return this.userRepository.findById(mongodbId).orElse(null);
    }

    public List<User> viewAllUsers(){

        return this.userRepository.findAll();

    }

    public void deleteUser(String mongodbId){
        this.userRepository.deleteById(mongodbId);
    }
}
